package com.sugar.follow.up.module.business.controller.app.record;

import com.sugar.follow.up.framework.common.pojo.CommonResult;
import com.sugar.follow.up.framework.common.pojo.PageParam;
import com.sugar.follow.up.framework.common.pojo.PageResult;
import com.sugar.follow.up.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.follow.up.module.business.controller.app.record.vo.AppRecordAnswerReqVO;
import com.sugar.follow.up.module.business.controller.app.record.vo.AppRecordDetailRespVO;
import com.sugar.follow.up.module.business.controller.app.record.vo.AppRecordPageRespVO;
import com.sugar.follow.up.module.business.controller.app.record.vo.AppRecordRespVO;
import com.sugar.follow.up.module.business.service.user.BizUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.sugar.follow.up.framework.common.pojo.CommonResult.successApp;

@Tag(name = "APP - 问卷与随访记录")
@RestController
@RequestMapping("/biz/record")
@Validated
public class AppRecordController {

    @Resource
    private BizUserService userService;

    @GetMapping("/all")
    @Operation(summary = "获得全部待办")
    @Parameter(name = "count", description = "查询数量，不传查全部", required = false, example = "1")
    public CommonResult<List<AppRecordRespVO>> getRecordAll(@RequestParam(value = "count", required = false) Integer count) {
        return successApp(userService.getRecordAll(count, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/get")
    @Operation(summary = "获得问卷/随访详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @Parameter(name = "type", description = "类型（1问卷 2随访）", required = true, example = "1")
    public CommonResult<AppRecordDetailRespVO> getRecordDetail(@RequestParam("id") Long id,
                                                               @RequestParam("type") Integer type) {
        return successApp(userService.getRecordDetail(id, type));
    }

    @GetMapping("/page")
    @Operation(summary = "获取问卷/随访分页")
    public CommonResult<PageResult<AppRecordPageRespVO>> getRecordPage(@Valid PageParam pageParam) {
        return successApp(userService.getRecordPage(pageParam, SecurityFrameworkUtils.getLoginUserId()));
    }

    @PostMapping("/answer")
    @Operation(summary = "答题")
    public CommonResult<Boolean> answerQuestion(@RequestBody @Valid AppRecordAnswerReqVO reqVO) {
        userService.answerQuestion(reqVO, SecurityFrameworkUtils.getLoginUserId());
        return successApp(true);
    }
}